<script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from '../components/HelloWorld.vue'
import { ref, onMounted, reactive, defineComponent } from 'vue'
import RecursiveMenu from '@/views/Help/RecursiveMenu.vue'
import axios from 'axios';
import { readB } from '@/http/axiosHelper'
import { ArrowLeft, Bell, SwitchButton, User } from '@element-plus/icons-vue'
const UserInfo = ref({
    id: localStorage.getItem("id"),
    userName: localStorage.getItem("userName"),
    userNick: localStorage.getItem("roleName")
})


onMounted(() => {
    GetMenus();
})

const rIe = ref(localStorage.getItem("roleId"))


//用户角色id 获取对应的菜单
const GetMenus = () => {
    readB.get("/api/RoleMenus/Menus", {
        params: {
            RIe: rIe.value
        }
    })
        .then(res => {
            menuData.value = res.data.data
        })
}


const menuData = ref([])

const activeIndex = ref('/ShowRole')
const handleSelect = (key: string) => {

}

// 退出登录方法
const handleLogout = () => {
    localStorage.clear()
    window.location.href = '/'
}
</script>

<template>
    <el-container class="main-container">
        <!-- 左侧菜单 -->
        <el-aside width="250px" class="sidebar">
            <!-- 顶部工作台区域 -->
            <div class="workbench-header">
                <span class="workbench-title">工作台</span>
                <el-icon class="collapse-icon"><ArrowLeft /></el-icon>
            </div>
            
            <!-- 主菜单 -->
            <el-menu 
                :default-active="activeIndex" 
                class="sidebar-menu" 
                mode="vertical" 
                background-color="#545c64"
                text-color="#fff" 
                active-text-color="#ffd04b" 
                @select="handleSelect" 
                router>
                
                <!-- 使用递归菜单组件 -->
                <RecursiveMenu :menus="menuData" />
            </el-menu>
            
            <!-- 底部功能区域 -->
            <div class="bottom-section">
          
                
                <!-- 退出登录 -->
                <div class="logout-item" @click="handleLogout">
                    <el-icon class="logout-icon"><SwitchButton /></el-icon>
                    <span class="logout-text">退出</span>
                </div>
                
                <!-- 用户信息 -->
                <div class="user-profile">
                    <el-icon class="user-icon"><User /></el-icon>
                    <span class="user-name">{{ UserInfo.userName }}</span>
                </div>
            </div>
        </el-aside>

        <!-- 右侧内容区域 -->
        <el-main class="main-content">
            <RouterView />
        </el-main>
    </el-container>
</template>


<style scoped>
.main-container {
    height: 100vh;
    width: 100%;
}

.sidebar {
    background-color: #545c64;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 1000;
}

/* 顶部工作台区域 */
.workbench-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid #4a4a4a;
    background-color: #4a4a4a;
}

.workbench-title {
    color: #fff;
    font-size: 16px;
    font-weight: 500;
}

.collapse-icon {
    color: #fff;
    cursor: pointer;
}

/* 主菜单区域 */
.sidebar-menu {
    flex: 1;
    border-right: none;
    background-color: #545c64;
}

.sidebar-menu .el-menu-item,
.sidebar-menu .el-sub-menu__title {
    height: 50px;
    line-height: 50px;
    padding: 0 20px;
    color: #fff;
}

.sidebar-menu .el-sub-menu .el-menu-item {
    padding-left: 40px;
}

/* 底部功能区域 */
.bottom-section {
    border-top: 1px solid #4a4a4a;
    background-color: #545c64;
    margin-top: auto;
    padding-bottom: 10px;
}

.notification-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    cursor: pointer;
    transition: background-color 0.3s;
    border-bottom: 1px solid #4a4a4a;
}

.notification-item:hover {
    background-color: #4a4a4a;
}

.notification-icon {
    color: #ccc;
    margin-right: 10px;
    font-size: 16px;
    display: flex;
    align-items: center;
}

.notification-text {
    color: #fff;
    flex: 1;
    font-size: 14px;
}

.notification-badge {
    margin-left: auto;
}

.notification-badge .el-badge__content {
    background-color: #ff6b6b;
}

.logout-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    cursor: pointer;
    transition: background-color 0.3s;
    border-top: 1px solid #4a4a4a;
}

.logout-item:hover {
    background-color: #4a4a4a;
}

.logout-icon {
    color: #ccc;
    margin-right: 10px;
    font-size: 16px;
}

.logout-text {
    color: #fff;
}

.user-profile {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background-color: #4a4a4a;
    border-top: 1px solid #3a3a3a;
}

.user-icon {
    color: #ccc;
    margin-right: 10px;
    font-size: 16px;
}

.user-name {
    color: #ccc;
    font-size: 14px;
}

/* 右侧内容区域 */
.main-content {
    padding: 0;
    overflow-y: auto;
    background-color: transparent;
    margin-left: 250px;
    min-height: 100vh;
}
</style>